/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ucm;

import sql.Update;

/**
 *
 * @author Donghui
 */
public class UpdateCard {

    private static UpdateCard local;
    private String msg;
    private String[] data;
    private String sql;
    private String response;
    private String tp;

    public static UpdateCard getInstance(String tp) {
        if (local == null) {
            local = new UpdateCard();
            local.msg = tp;
        } else {
            local.msg = tp;
        }
        return local;
    }

    public String modifyRFID() {
        try {
            data = msg.split(";");
            sql = "UPDATE rfid SET roll_id='', psw='' WHERE roll_id='" + data[0] + "'";
            response = Update.getInstance().updateValue(sql);
            if (response.equalsIgnoreCase("1")) {
                sql = "UPDATE rfid,roll SET rfid.roll_id='" + data[0] + "',rfid.psw='" + data[2] + "',roll.card_id='" + data[1] + "' WHERE rfid.cid='" + data[1] + "' AND roll.id='" + data[0] + "'";
                response = Update.getInstance().updateValue(sql);
                if (response.equalsIgnoreCase("1")) {
                    tp = "Y;11";
                } else {
                    tp = "N;11";
                }
            } else {
                tp = "N;11";
            }
        } catch (Exception e) {
            e.printStackTrace();
            tp = "N;11";
        }
        return tp;
    }
}
